home *** CD-ROM | disk | FTP | other *** search
/ Super PC 33 / Super PC 33 (Shareware).iso / spc / sonido / timidity / source / output.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-06  |  3.5 KB  |  201 lines

  1. /*
  2.  
  3.     TiMidity -- Experimental MIDI to WAVE converter
  4.     Copyright (C) 1995 Tuukka Toivonen <titoivon@snakemail.hut.fi>
  5.  
  6.     This program is free software; you can redistribute it and/or modify
  7.     it under the terms of the GNU General Public License as published by
  8.     the Free Software Foundation; either version 2 of the License, or
  9.     (at your option) any later version.
  10.  
  11.     This program is distributed in the hope that it will be useful,
  12.      but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.     GNU General Public License for more details.
  15.  
  16.      You should have received a copy of the GNU General Public License
  17.     along with this program; if not, write to the Free Software
  18.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  
  20.     output.c
  21.     
  22.     Audio output (to file / device) functions.
  23. */
  24.  
  25. #include "config.h"
  26. #include "output.h"
  27. #include "tables.h"
  28.  
  29. #ifdef AU_LINUX
  30. extern PlayMode linux_play_mode;
  31. #define DEFAULT_PLAY_MODE &linux_play_mode
  32. #endif
  33.  
  34. #ifdef AU_HPUX
  35. extern PlayMode hpux_play_mode;
  36. #define DEFAULT_PLAY_MODE &hpux_play_mode
  37. #endif
  38.  
  39. #ifdef AU_SUN
  40. extern PlayMode sun_play_mode;
  41. #define DEFAULT_PLAY_MODE &sun_play_mode
  42. #endif
  43.  
  44. #ifdef AU_WIN32
  45. extern PlayMode win32_play_mode;
  46. #define DEFAULT_PLAY_MODE &win32_play_mode
  47. #endif
  48.  
  49. extern PlayMode raw_play_mode, wave_play_mode;
  50.  
  51. PlayMode *play_mode_list[] = {
  52. #ifdef DEFAULT_PLAY_MODE
  53.   DEFAULT_PLAY_MODE,
  54. #endif
  55.   &wave_play_mode,
  56.   &raw_play_mode,
  57.   0
  58. };
  59.  
  60. #ifdef DEFAULT_PLAY_MODE
  61.   PlayMode *play_mode=DEFAULT_PLAY_MODE;
  62. #else
  63.   PlayMode *play_mode=&wave_play_mode;
  64. #endif
  65.  
  66. /*****************************************************************/
  67. /* Some functions to convert signed 32-bit data to other formats */
  68.  
  69. void s32tos8(int32 *lp, void *b, int32 c)
  70. {
  71.   int8 *cp;
  72.   int32 l;
  73.  
  74.   if (b)
  75.     cp = b;
  76.   else
  77.     cp = (int8 *)(lp);
  78.  
  79.   while (c--)
  80.      {
  81.         l=(*lp++)>>(32-8-GUARD_BITS);
  82.         if (l>127) l=127;
  83.         else if (l<-128) l=-128;
  84.         *cp++ = (int8) (l);
  85.      }
  86. }
  87.  
  88. void s32tou8(int32 *lp, void *b, int32 c)
  89. {
  90.   uint8 *cp;
  91.   int32 l;
  92.  
  93.   if (b)
  94.     cp = b;
  95.   else
  96.     cp = (uint8 *)(lp);
  97.  
  98.   while (c--)
  99.      {
  100.         l=(*lp++)>>(32-8-GUARD_BITS);
  101.         if (l>127) l=127;
  102.         else if (l<-128) l=-128;
  103.         *cp++ = 0x80 ^ ((uint8) l);
  104.      }
  105. }
  106.  
  107. void s32tos16(int32 *lp, void *b, int32 c)
  108. {
  109.   int16 *sp;
  110.   int32 l;
  111.  
  112.   if (b)
  113.     sp = b;
  114.   else
  115.     sp = (int16 *)(lp);
  116.  
  117.   while (c--)
  118.      {
  119.         l=(*lp++)>>(32-16-GUARD_BITS);
  120.         if (l > 32767) l=32767;
  121.         else if (l<-32768) l=-32768;
  122.         *sp++ = (int16)(l);
  123.      }
  124. }
  125.  
  126. void s32tou16(int32 *lp, void *b, int32 c)
  127. {
  128.   uint16 *sp;
  129.   int32 l;
  130.  
  131.   if (b)
  132.     sp = b;
  133.   else
  134.     sp = (uint16 *)(lp);
  135.  
  136.   while (c--)
  137.      {
  138.         l=(*lp++)>>(32-16-GUARD_BITS);
  139.         if (l > 32767) l=32767;
  140.         else if (l<-32768) l=-32768;
  141.         *sp++ = 0x8000 ^ (uint16)(l);
  142.      }
  143. }
  144.  
  145. void s32tos16x(int32 *lp, void *b, int32 c)
  146. {
  147.   int16 *sp;
  148.   int32 l;
  149.  
  150.   if (b)
  151.     sp = b;
  152.   else
  153.     sp = (int16 *)(lp);
  154.  
  155.   while (c--)
  156.      {
  157.         l=(*lp++)>>(32-16-GUARD_BITS);
  158.         if (l > 32767) l=32767;
  159.         else if (l<-32768) l=-32768;
  160.         *sp++ = XCHG_SHORT((int16)(l));
  161.      }
  162. }
  163.  
  164. void s32tou16x(int32 *lp, void *b, int32 c)
  165. {
  166.   uint16 *sp;
  167.   int32 l;
  168.  
  169.   if (b)
  170.     sp = b;
  171.   else
  172.     sp = (uint16 *)(lp);
  173.  
  174.   while (c--)
  175.      {
  176.         l=(*lp++)>>(32-16-GUARD_BITS);
  177.         if (l > 32767) l=32767;
  178.         else if (l<-32768) l=-32768;
  179.         *sp++ = XCHG_SHORT(0x8000 ^ (uint16)(l));
  180.      }
  181. }
  182.  
  183. void s32toulaw(int32 *lp, void *b, int32 c)
  184. {
  185.   uint8 *up;
  186.   int32 l;
  187.  
  188.   if (b)
  189.     up = b;
  190.   else
  191.     up = (uint8 *)(lp);
  192.  
  193.   while (c--)
  194.      {
  195.         l=(*lp++)>>(32-13-GUARD_BITS);
  196.         if (l > 4095) l=4095;
  197.         else if (l<-4096) l=-4096;
  198.         *up++ = _l2u[l];
  199.      }
  200. }
  201.